#include "StdAfx.h"
#include "YDbCmd.h"

#include "..\DataBase\include\UDataBase.h"
#include "..\DataLayer\YUserInfo.h"
#include <atlconv.h>
#include <AFXCONV.H> 


YDbCmd::YDbCmd(void)
{
}

YDbCmd::~YDbCmd(void)
{
}

COleDateTime YDbCmd::GetServerDateTime(void)
{
	COleDateTime dt;
	CString strSql = _T("select getdate()");
	CADORecordset *pRecordset = new CADORecordset();
	BOOL bResult = UDataBase::GetDataBase()->GetRecordData(pRecordset, strSql);
	if (bResult && pRecordset->GetFieldCount() > 0)
	{
		pRecordset->GetFieldValue(0, dt);
	}
	pRecordset->Close();
	delete pRecordset;

	return dt;
}

BOOL YDbCmd::GetUserInfoByNameAndPwd(YUserInfo* pYUserInfo)
{
	CADORecordset* pRecordset = new CADORecordset();
	CString strSql;
	strSql.Format( _T("select * from ys_user where ur_name=\'%s\' and ur_password=\'%s\'"),pYUserInfo->GetName(),pYUserInfo->GetPassword() );
	BOOL bRet = UDataBase::GetDataBase()->GetRecordData(pRecordset,strSql);
	if ( !pRecordset->IsEof() )
	{
		int nId = 0;
		int ur_dr_id = 0;
		CString strName = _T("");
		CString strPassword = _T("");
		CString strTel = _T("");
		bool ur_temp = false;
		COleDateTime tStart;
		COleDateTime tEnd;
		pRecordset->GetFieldValue( _T("ur_id"),nId);
		pRecordset->GetFieldValue( _T("ur_dr_id"),ur_dr_id);
		pRecordset->GetFieldValue( _T("ur_name"),strName);
		pRecordset->GetFieldValue( _T("ur_password"),strPassword);
		pRecordset->GetFieldValue( _T("ur_tel"),strTel);
		pRecordset->GetFieldValue( _T("ur_temp"),ur_temp);
		pRecordset->GetFieldValue( _T("ur_enddate"),tEnd);
		pRecordset->GetFieldValue( _T("ur_startdate"),tStart);
		pYUserInfo->SetId(nId);
		pYUserInfo->SetDrId(ur_dr_id);
		USES_CONVERSION; 
		pYUserInfo->SetName( T2A(strName) );
		pYUserInfo->SetPassword( T2A(strPassword) );
		pYUserInfo->SetTel( T2A(strTel) );
		pYUserInfo->SetTemp( ur_temp );
		pYUserInfo->SetStartTime( tStart );
		pYUserInfo->SetEndTime( tEnd );
	}
	else
	{
		bRet = FALSE;
	}
	pRecordset->Close();
	delete pRecordset;
	pRecordset = NULL;
	return bRet;
}











































